package com.lrkj.payfee.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.payfee.domain.AdvanceReceipt;
import com.lrkj.payfee.domain.AgainstRecord;
import com.lrkj.payfee.service.IAdvanceReceiptService;
import com.lrkj.payfee.service.IAgainstRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预收单Controller
 *
 * @author yajun_ren
 * @date 2021-08-06
 */
@RestController
@RequestMapping("/payfee/advanceReceipt")
public class AdvanceReceiptController extends BaseController {
    @Autowired
    private IAdvanceReceiptService advanceReceiptService;

    @Autowired
    private IAgainstRecordService againstRecordService;

    /**
     * 查询预收单列表
     */
    @ApiOperation(value = "查询预收单列表", notes = "查询预收单列表")
    @PreAuthorize("@ss.hasPermi('payfee:advanceReceipt:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdvanceReceipt advanceReceipt) {
        startPage();
        List<AdvanceReceipt> list = advanceReceiptService.selectAdvanceReceiptList(advanceReceipt);
        return getDataTable(list);
    }

    /**
     * 导出预收单列表
     */
    @ApiOperation(value = "导出预收单列表", notes = "导出预收单列表")
    @PreAuthorize("@ss.hasPermi('payfee:advanceReceipt:export')")
    @Log(title = "预收单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdvanceReceipt advanceReceipt) {
        List<AdvanceReceipt> list = advanceReceiptService.selectAdvanceReceiptList(advanceReceipt);
        ExcelUtil<AdvanceReceipt> util = new ExcelUtil<AdvanceReceipt>(AdvanceReceipt.class);
        return util.exportExcel(list, "预收单数据");
    }

    /**
     * 获取预收单详细信息
     */
    @ApiOperation(value = "获取预收单详细信息", notes = "获取预收单详细信息")
    @PreAuthorize("@ss.hasPermi('payfee:advanceReceipt:query')")
    @GetMapping(value = "/{madvanceReceiptId}")
    public AjaxResult getInfo(@PathVariable("madvanceReceiptId") String madvanceReceiptId) {
        return AjaxResult.success(advanceReceiptService.selectAdvanceReceiptById(madvanceReceiptId));
    }

    /**
     * 通过房屋IDS获取预收金额
     */
    @ApiOperation(value = "通过房屋IDS获取预收金额", notes = "通过房屋IDS获取预收金额")
    @GetMapping(value = "/getAdvanceMoney/{roomIds}")
    public AjaxResult getAdvanceMoney(@PathVariable("roomIds") String roomIds) {
        return AjaxResult.success(advanceReceiptService.getAdvanceMoney(roomIds));
    }


    /**
     * 查询预收冲抵记录列表
     */
    @ApiOperation(value = "查询预收冲抵记录列表", notes = "查询预收冲抵记录列表")
    @GetMapping("/againstRecordList")
    public TableDataInfo againstRecordList(AgainstRecord advanceReceipt) {
        startPage();
        List<AgainstRecord> list = againstRecordService.selectAgainstRecordList(advanceReceipt);
        return getDataTable(list);
    }


    /**
     * 预收款退款
     */
    @ApiOperation(value = "预收款退款", notes = "预收款退款")
    @GetMapping(value = "/advanceRefund/{madvanceReceiptIds}")
    public AjaxResult advanceRefund(@PathVariable("madvanceReceiptIds") String[] madvanceReceiptIds) {
        return AjaxResult.success(advanceReceiptService.advanceRefund(madvanceReceiptIds));
    }

    /**
     * 通过业主查询预收款余额
     */
    @ApiOperation(value = "通过业主查询预收款余额", notes = "通过业主查询预收款余额")
    @PostMapping("/getAmountRemaining")
    public AjaxResult getAmountRemaining(@RequestBody AdvanceReceipt advanceReceipt) {
        return AjaxResult.success(advanceReceiptService.getAmountRemaining(advanceReceipt));
    }

}
